<%--
  Created by IntelliJ IDEA.
  User: syx
  Date: 2021/12/20
  Time: 9:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/fileupload.js"></script>
</head>
<body>

    添加
    <form>
        制单人工号:<input type="text" name="uid" value="${user.uid}"><br>
        制单人:<input type="text" value="${user.uname}"><br>
        商品归属:<input type="text" name="asc"><br>
        商品名称:<input type="text" name="sname"><br>
        类型:
        <select id="txl">
            <option>请选择</option>
        </select>
        <br>
        品牌:
        <select id="pxl">
            <option>请选择</option>
        </select>
        <br>
        图片:
        <div class="photoUpLoad" >
            <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
            <img src="" alt="" class="photoEcho" width="150px" height="150px">
        </div>
        <br>
        型号:<input type="text" name="mods"><br>
        规格:<input type="text" name="spe"><br>
        单价:<input type="text" name="price"><br>
    </form>
    <button onclick="add()">添加</button>
</body>
<script>
    $(function () {
          $.ajax({
              url:"type.do",
              type:"post",
              dataType:"json",
              success:function (obj) {
                  console.log(obj)
                  for (let i in obj) {
                      $("#txl").append('<option name=tid value='+obj[i].tid+'>'+obj[i].tname+'</option>')
                  }
              }
          })
        $.ajax({
            url:"brand.do",
            type:"post",
            dataType:"json",
            success:function (obj) {
                console.log(obj)
                for (let i in obj) {
                    $("#pxl").append('<option name="tid" value="'+obj[i].pid+'">'+obj[i].pname+'</option>')
                }
            }
        })
    })
    function add(){
        var val = $("[name='tid']").val();
        alert(val);
        var formData = new FormData($("form")[0]);
        console.log(formData)
          $.ajax({
              url:"add.do",
              type:"post",
              data:formData,
              dataType:"json",
              success:function (obj) {
                  console.log(obj)
                  if (obj>0){
                      alert("添加成功!!")
                      location="list.do"
                  }
              },
              processData:false,
              contentType:false,
          })
    }
</script>
</html>
